package com.wzw.springboot.principle;

import com.wzw.springboot.principle.aop.Stu;
import com.wzw.springboot.principle.aop.Target;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * @author wangzhiwen
 */
@EnableCaching
@EnableScheduling
@EnableAspectJAutoProxy
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
// @SpringBootApplication
// @EnableAspectJAutoProxy(exposeProxy = true)
// @EnableTransactionManagement(proxyTargetClass = true, mode = AdviceMode.ASPECTJ)
public class SpringBootPrincipleApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringBootPrincipleApplication.class, args);

        /* AOP 切面编程 */
        Target target = context.getBean(Target.class);
        target.service(new Stu().setId(101L).setUuid("WZW"));

        /* 注解方式的动态数据源 */
        // UseService useService = context.getBean(UseService.class);
        // useService.addUser();

        /*CacheTest*/
        // CacheTestService cacheTestService = context.getBean(CacheTestService.class);
        // String testCaffeineCache = cacheTestService.testCaffeineCache("testCaffeineCache");
        // String testCaffeineCache1 = cacheTestService.testCaffeineCache("testCaffeineCache");
        //
        // String testRedisCache = cacheTestService.testRedisCache("testRedisCache");
        // String testRedisCache1 = cacheTestService.testRedisCache("testRedisCache");
        //
        // cacheTestService.testCaffeineClenCache("testCaffeineCache");
        // cacheTestService.testRedisClenCache("testRedisCache");

        /* Redis lock Test */
        // RedisLockTest redisLockTest = context.getBean(RedisLockTest.class);
        // 基于Redis setnx
        // redisLockTest.test1();
        // 基于Redisson
        // redisLockTest.test2();

        /* SPEL AOP */
        // PermissionTestService permissionTestService = context.getBean(PermissionTestService.class);
        // permissionTestService.testSpel1("test pass");
        // permissionTestService.testSpel2("test pass");

        /* 基于Spring的事件发布 */
        // EventPublishHandler.publishEvent(new PrincipleEvent("source", "SOURCE_ID"));

        // canal 数据同步
        // CanalClient client = new CanalClient();
        // client.start();

        // spring-batch
        // JobLauncher launcher = CustomApplicationContext.getBean(JobLauncher.class);
        // Job job = CustomApplicationContext.getBean("simplePersonProcessJob", Job.class);
        // JobParameters jobParameters = new JobParametersBuilder().addString("testJob", "8989").toJobParameters();
        // try {
        //     JobExecution jobExecution = launcher.run(job, jobParameters);
        //     BatchStatus status = jobExecution.getStatus();
        //     System.out.println(status);
        // } catch (JobExecutionAlreadyRunningException | JobParametersInvalidException | JobRestartException | JobInstanceAlreadyCompleteException e) {
        //     e.printStackTrace();
        // }
    }

}